import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:vehicle_management/pages/my_task_page/ServiceLocator.dart';
import 'package:vehicle_management/routes/routes.dart';
import 'package:vehicle_management/public.dart';

void main() {
// 注册服务打电话
  setupLocator();
  WidgetsFlutterBinding.ensureInitialized(); //不加这个强制横/竖屏会报错
  SystemChrome.setPreferredOrientations([
    // 强制竖屏
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown
  ]);
  setupApp();
}

setupApp() async {
  preferences = await SharedPreferences.getInstance();
  print("初始化数据");
  // 运行主界面
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    var isLogin = preferences.getString("appKey");
    return MaterialApp(
        title: '久顺物流',
        theme: ThemeData(
          primarySwatch: Colors.red,
        ),
        initialRoute: isLogin ==null ?'/':'/Home',
        onGenerateRoute: onGenerateRoute);
  }
}
